<admintpl file="header"/></head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:U('index')}">{:L("COUPON_LIST")}</a></li>
        <li class="active"><a><eq name="is_add" value="1">{:L("COUPON_ADD")}<else/>{:L("COUPON_UPD")}</eq></a></li>
    </ul>
    <form class="form-horizontal js-ajax-form" method="post">
        <fieldset>
            <div class="tabbable">
                <div class="tab-content">
                    <fieldset>
                        <div class="control-group">
                            <label class="control-label">优惠券名称</label>
                            <div class="controls">
                                <input type="text" name="options[name]" class="" size="11" value="{$data['name']}"/>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">优惠券数量</label>
                            <div class="controls">
                                <input type="number" name="options[quantity]" class="" size="11" placeholder="请输入整数" value="{$data['quantity']}"/>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">有效天数</label>
                            <div class="controls">
                                <input type="number" name="options[effective_days]" class="" size="11" placeholder="请输入正整数" value="{$data['effective_days']?$data['effective_days']:0}"/>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">单人限领一次</label>
                            <div class="controls">
                                <select id="is_single" name="options[is_single]">
                                    <option value="1">是</option>
                                    <option value="0">否</option>
                                </select>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">减免金额</label>
                            <div class="controls">
                                <input type="text" name="options[amount]" class="" size="11" placeholder="请输入数字" value="{$data['amount']}"/>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">状态</label>
                            <div class="controls">
                                <select id="status" name="options[status]">
                                    <option value="1">已启用</option>
                                    <option value="0">未启用</option>
                                    <option value="2">已结束</option>
                                </select>
                            </div>
                        </div>
                    </fieldset>
                </div>
            </div>

            <div class="form-actions">
                <button class="btn btn-primary js-ajax-submit" type="submit" data-types='1' data-action="<if condition='$is_add == 1'>{:U('add')}<else/>{:U('upd',['id'=>I('get.id')])}</if>" data-msg='确认提交?' data-subcheck="true">提交</button>
                <a class="btn btn-primary js-ajax-submit" href="{:U('index')}">返回</a>
            </div>
        </fieldset>
    </form>

</div>
<script src="__PUBLIC__/js/common.js"></script>
</body>
<script type="text/javascript">

    $(function(){
        $('#is_single').find('option[value="'+'{$data["is_single"]}'+'"]').prop('selected',true);
        $('#status').find('option[value="'+'{$data["status"]}'+'"]').prop('selected',true);
    });

    var ajaxForm_list = $('form.js-ajax-form');
    if (ajaxForm_list.length) {
        Wind.use('ajaxForm', 'artDialog', function () {

            $('button.js-ajax-submit').bind('click', function (e) {

                e.preventDefault();
                /*var btn = $(this).find('button.js-ajax-submit'),
                        form = $(this);*/
                var btn = $(this),
                    form = btn.parents('form.js-ajax-form');

                //批量操作 判断选项
                if (btn.data('subcheck')) {
                    btn.parent().find('span').remove();
                    var msg = btn.data('msg');
                    if (msg) {
                        art.dialog({
                            id: 'warning',
                            icon: 'warning',
                            content: btn.data('msg'),
                            cancelVal: "{:L('CLOSE')}",
                            cancel: function () {

                            },
                            button: [{
                                name: "{:L('OK')}",
                                callback: function () {
                                    ajaxSubmit(btn.data('types'));
                                },
                                focus: true
                            }]
                        });
                    } else {
                        btn.data('subcheck', false);
                        btn.click();
                    }
                    return false;
                }
            });

        });
    }

    function ajaxSubmit(type) {
        var btn = $('button.js-ajax-submit'),
            form = btn.parents('form.js-ajax-form');
        form.ajaxSubmit({
            url: type ? btn.data('action') : form.attr('action'),
            //按钮上是否自定义提交地址(多按钮情况)
            dataType: 'json',
            beforeSubmit: function (arr, $form, options) {
                // var tx = type ? '添加' : '审核不通过';
                var tx = '提交';
                //按钮文案、状态修改
                btn.text(tx + '中...').attr('disabled', true).addClass('disabled');
            },
            success: function (data, statusText, xhr, $form) {
                //按钮文案、状态修改
                btn.removeClass('disabled').parent().find('span').remove();

                if (data.state === 'success') {
                    $('<span class="tips_success">' + data.info + '</span>').appendTo(btn.parent()).fadeIn('slow').delay(1000).fadeOut(function () {
                        if (data.referer) {
                            //返回带跳转地址
                            if (window.parent.art) {
                                //iframe弹出页
                                window.parent.location.href = data.referer;
                            } else {
                                window.location.href = data.referer;
                            }
                        } else {
                            if (window.parent.art) {
                                reloadPage(window.parent);
                            } else {
                                //刷新当前页
                                reloadPage(window);
                            }
                        }
                    });
                } else if (data.state === 'fail') {
                    $('<span class="tips_error">' + data.info + '</span>').appendTo(btn.parent()).fadeIn('fast');

                    btn.text('提交').removeProp('disabled').removeClass('disabled');
                }
            }
        });
    }
</script></html>